package net.sourceforge.jweb.jstl.easyui;

import java.io.IOException;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import net.sourceforge.jweb.annotation.Attribute;
import net.sourceforge.jweb.annotation.Tag;
import net.sourceforge.jweb.jstl.helper.JstlUtil;
import net.sourceforge.jweb.util.FreeMarkerUtil;

@Tag(name = "gridAssociation", description = "master detail grid association tag, used for create multiple grid association")
public class GridAssociationTag extends SimpleTagSupport {
	private String event = "*";
	private String master;
	private String field = "null";

	@Override
	public void doTag() throws JspException, IOException {
		DataGridTag grid = (DataGridTag) this.getParent();
		Map<String, Object> params = JstlUtil.tagAttibuteMap(this);
		params.put("gridId", grid.getGridId());
		grid.otherCodeBlocks.add(FreeMarkerUtil.processTemplate("grid-pagebus-subscriber.fmt", params));
		super.doTag();
	}

	@Attribute(required = false, description = "the event you are subscribing, support wildcard, default is *, now onCheck, onUncheck, onCheckAll, onUncheckAll, onLoadSuccess events are supported")
	public String getEvent() {
		return event;
	}

	public void setEvent(String event) {
		this.event = event;
	}

	@Attribute(required = true, description = "master grid id you are subscribe")
	public String getMaster() {
		return master;
	}

	public void setMaster(String master) {
		this.master = master;
	}

	@Attribute(required = true, description = "filed name you are using for http request")
	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}
}
